var vm_zhuanjiabiandongpici = new Vue({
    el : "#zhuanjiabiandongpici",
    data : {
        deptid : $("#deptid").val(),		// 单位ID

        biandongpicilist : [],// 专家变动列表custom
        biandongpiciid : '',//变动id
        biandongpici : {},//变动表

        //查询用字段
        picimingcheng : '',

        //
        editflag : '',

    },
    created : function(){
        var _this = this;

        _this.bindBiandongPiciList();

    },
    methods : {

        // 根据单位ID查询下级单位
        bindBiandongPiciList : function(){
            var _this = this;

            var biandongpici_layer = layer.open({type:3});
            $.post('/system/zhuanjiabiandongpici/find_custom_list', {
                deptid : _this.deptid,
                picimingcheng : _this.picimingcheng,
                rdm : Math.random()
            },function(ppData) {
                layer.close(biandongpici_layer);

                if (ppData != null) {
                    if (ppData.result==1){
                        var data = ppData.resultContent;
                        _this.biandongpicilist = data;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        toAdd:function(){

            $("#myModalLabel").html("添加专家变动批次");
            $("#modal-dialog").attr("style","width:1200px;");
            $("#biandongpiciModal").modal();

            this.biandongpici = {};
            this.editflag = 1;
        },

        //暂时没用
        add : function(){
            var _this = this;

            if (_this.checkInputData()) {
                var biandongpici_layer = layer.open({type:3});
                $.post('/system/zhuanjiabiandongpici/customadd', {
                    deptid : _this.deptid,
                    picimingcheng : _this.biandongpici.picimingcheng,
                    rdm : Math.random()
                },function(ppData) {
                    layer.close(biandongpici_layer);

                    if (ppData != null) {
                        if (ppData.result==1){
                            var data = ppData.resultContent;
                            layer.open({
                                time: 1000,
                                btn: [],
                                content: "添加成功!",
                            });

                            _this.bindBiandongPiciList();
                            $("#biandongpiciModal").modal('hide');
                        }else{
                            layer.alert(ppData.message);
                        }
                    }
                }, "json");
            }
        },

        toModify:function(ppID){

            $("#myModalLabel").html("修改专家变动批次");
            $("#modal-dialog").attr("style","width:1200px;");
            $("#biandongpiciModal").modal();

            this.biandongpiciid = ppID;

            this.biandongpici = {};
            this.editflag = 2;
            // 绑定变动
            this.bindBiandongpici();
        },

        // 修改信息
        modify : function(){
            var _this = this;
            if (_this.checkInputData()) {
                var biandong_layer = layer.open({type: 3});
                $.post('/system/zhuanjiabiandongpici/edit', {
                    id: _this.biandongpiciid,
                    picimingcheng : _this.biandongpici.picimingcheng,
                    rdm: Math.random()
                }, function (ppData) {
                    layer.close(biandong_layer);
                    if (ppData != null) {

                        if (ppData.code == "0") {

                            layer.open({
                                time: 1000,
                                btn: [],
                                content: "修改成功!",
                            });

                            _this.bindBiandongPiciList();
                            $("#biandongpiciModal").modal('hide');

                        } else {
                            layer.alert(ppData.msg);
                        }
                    }
                }, "json");
            }
        },

        bindBiandongpici:function(){
            var _this = this;

            var biandong_layer = layer.open({type:3});
            $.post('/system/zhuanjiabiandongpici/findone', {
                id : _this.biandongpiciid,
                rdm : Math.random()
            },function(ppData) {
                layer.close(biandong_layer);

                if(ppData != null){

                    if(ppData.result == "1"){
                        _this.biandongpici = ppData.resultContent;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        Delete:function(ppId){
            var _this = this;

            var biandong_layer = layer.open({type:3});
            $.post('/system/zhuanjiabiandongpici/remove', {
                ids : ppId,
                rdm : Math.random()
            },function(ppData) {
                layer.close(biandong_layer);

                if(ppData != null){

                    if(ppData.code == "0"){
                        layer.open({
                            time: 1000,
                            btn: [],
                            content: "删除成功!",
                        });

                        _this.bindBiandongPiciList();
                    }else{
                        layer.alert(ppData.msg);
                    }
                }
            },"json");
        },

        //检查项目数据
        checkInputData : function() {
            if (!$.trim(this.biandongpici.picimingcheng)) {
                layer.alert("请填写变动批次名称！");
                return false;
            }

            return true;
        },

        //专家变动详情列表
        toBiandongDetail : function(ppBiandongpiciId,ppBiandongpiciMingcheng){
            $.modal.openTab(ppBiandongpiciMingcheng+"详情",'/system/zhuanjiabiandongdetail/customzhuanjiabiandongdetail?piciid='+ppBiandongpiciId,false);
        },

        //检查是否已创建变动批次，没有：创建，有：跳转  暂时没用
        toCheckBiandongpici:function(ppBiandongpiciItem){

            var _this = this;

            var mmBiandongpiciid = ppBiandongpiciItem.id;
            var mmBiandongpiciMingcheng = ppBiandongpiciItem.picimingcheng;

            if (mmBiandongpiciid!=null){
                $.modal.openTab(mmBiandongpiciMingcheng+"详情",'/system/zhuanjiabiandongdetail/customzhuanjiabiandongdetail?piciid='+mmBiandongpiciid,false);
            }else if (mmBiandongpiciid==null){

                var biandongpici_layer = layer.open({type:3});
                $.post('/system/zhuanjiabiandongpici/customadd', {
                    deptid : _this.deptid,
                    beizhu1 : ppBiandongpiciItem.piciid,
                    rdm : Math.random()
                },function(ppData) {
                    layer.close(biandongpici_layer);

                    if (ppData != null) {
                        if (ppData.result==1){
                            var data = ppData.resultContent;
                            $.modal.openTab(data.picimingcheng+"详情",'/system/zhuanjiabiandongdetail/customzhuanjiabiandongdetail?piciid='+data.id,false);
                        }else{
                            layer.alert(ppData.message);
                        }
                    }
                });

            }
        },

    },
})